import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yuan_hang_app/base/base_state.dart';
import 'package:yuan_hang_app/base/full_base_page.dart';
import 'package:yuan_hang_app/utils/common_utils.dart';
import 'package:yuan_hang_app/utils/size_utils.dart';
import 'package:yuan_hang_app/widget/label_item.dart';

import '../../../../http/api.dart';
import '../../../../http/http_utils.dart';
import '../../../../res/w_colors.dart';
import '../../../../utils/router_helper.dart';
import '../../../../widget/w_text.dart';
import '../../../../widget/w_toast.dart';

class DefeatLeadsRejectPage extends StatefulWidget {
  final List<int> clueIds;
  const DefeatLeadsRejectPage({super.key, required this.clueIds});

  @override
  BaseState<DefeatLeadsRejectPage> createState() =>
      _DefeatLeadsRejectPageState();
}

class _DefeatLeadsRejectPageState extends BaseState<DefeatLeadsRejectPage> {

  String rejectReason = "";

  @override
  FullBasePage buildState(BuildContext context) {
    return FullBasePage(
        title: "驳回",
        child: Column(
       //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              margin: EdgeInsets.symmetric(horizontal: 15.px,vertical: 10.px),
              decoration:BoxDecoration(
                borderRadius: BorderRadius.circular(10.px),
                boxShadow: [
                  BoxShadow(
                      color: WColors.CDFEFFB,
                      offset: const Offset(0, 1),
                      blurRadius: 3.px),
                ]
              ),
              child: LabelItem(
                label: "驳回意见",
                labelType: LabelType.TEXTAREA,
                maxLine: 5,
                maxTextLength: 500,
                isLast: true,
                onChanged: (text) {
                  rejectReason = text;
                },
              ),
            ),

            GestureDetector(
              onTap: () {
                CommonUtils.throttle(defeatReject);
              },
              child: Container(
                margin:
                    EdgeInsets.symmetric(vertical: 16.px, horizontal: 10.px),
                width: SizeUtils.screenW() - 48.px,
                alignment: Alignment.center,
                height: 48.px,
                decoration: BoxDecoration(
                  color: WColors.primaryColor,
                  borderRadius: BorderRadius.circular(24.px),
                ),
                child: WText(
                  "保存",
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 16.px,
                  ),
                ),
              ),
            )
          ],
        ));
  }

  defeatReject() {
    Map params = {"clueIdList": widget.clueIds, "result": false, "noPassReason" : rejectReason};
    showLoading();
    HttpUtils().post(Api.examineOperator, data: params).then((value) {
      hideLoading();
      if (value.resultCode == 200) {
        Toast.toast("审核成功");
        RouteHelper.maybePop(context, true);
      } else {
        Toast.toast(value.errMsg);
      }
    });
  }
}
